import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../../helper.dart';
import '../logic.dart';
import 'item_widgets2.dart';

class ItemWidget1 extends StatefulWidget {
  //店铺下标
  int shopIndex;

  //商品数组下标
  int goodsListIndex;

  final OrderCreateLogic logic;

  ItemWidget1({Key key, this.shopIndex, this.goodsListIndex, this.logic})
      : super(key: key);

  @override
  _ItemWidget1State createState() => new _ItemWidget1State();
}

class _ItemWidget1State extends State<ItemWidget1> {
  List jiaobiao;

  @override
  void initState() {
    jiaobiao = widget.logic.state.cartData["multi_shop_items"][widget.shopIndex]
        ["cart_item_list"][widget.goodsListIndex]["item_promotion_list"];
  }
  @override
  Widget build(BuildContext context) {
    return Container(
      child: GetBuilder<OrderCreateLogic>(builder: (logic) {
        return Column(
          children: [
            Container(
              color: Colors.white,
              child: Column(
                children: [
                  Row(
                    children: [
                      if (jiaobiao.length > 0)
                        Container(
                          padding: EdgeInsets.symmetric(
                              horizontal: 15.w, vertical: 6.w),
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.only(
                                topLeft: Radius.circular(logic.state.angle[0]),
                                topRight: Radius.circular(logic.state.angle[1]),
                                bottomLeft:
                                    Radius.circular(logic.state.angle[2]),
                                bottomRight:
                                    Radius.circular(logic.state.angle[3])),
                            border: Border.all(
                              color: getColorFromHex(
                                  logic.state.promotion_cat['frame_color']),
                              width: 1.w,
                            ),
                            color: getColorFromHex(
                                logic.state.promotion_cat['tag_fgcolor']),
                          ),
                          child: Text(
                            // tag_name_type ==1 45 0 一口价
                            logic.state.promotion_cat != null
                                ? logic.state.promotion_cat['tag_name_type'] ==
                                        1
                                    ? "${jiaobiao[0]["corner_with_param"]}"
                                    : "${jiaobiao[0]["corner_with_no_param"]}"
                                : '',
                            style: TextStyle(
                              color: getColorFromHex(
                                  logic.state.promotion_cat['word_color']),
                              fontSize: 26.sp,
                              height: 1.3,
                            ),
                          ),
                        ),
                           SizedBox(
                   width: 10.w,
                 ),
                        Visibility(
                           visible: jiaobiao.length > 0,
                          child: Expanded(
                            child:
                            new Text(
                              jiaobiao.length > 0?'${jiaobiao[0]["corner_detail"]}':''
                            ,

                              overflow: TextOverflow.ellipsis, //长度溢出后显示省略号
                              maxLines: 1,
                              style: new TextStyle(
                                fontSize: 13.0,
                                fontFamily: 'Roboto',
                                color:Colors.grey,

                              ),
                            ),
                          ),
                        ),
                    ],
                  ),
                  ListView.builder(

                    itemBuilder: (ctx, index) {
                      return ItemWidget2(
                          shopIndex: widget.shopIndex,
                          goodsListIndex: widget.goodsListIndex,
                          index: index,
                          logic: logic);
                    },
                    shrinkWrap: true,
                    physics: NeverScrollableScrollPhysics(),
                    itemCount: logic
                        .state
                        .cartData["multi_shop_items"][widget.shopIndex]
                            ["cart_item_list"][widget.goodsListIndex]["items"]
                        .length,
                  ),
                ],
              ),
            )
          ],
        );
      }),
    );
  }
}
